package org.timeismoney.payment.common;

import java.util.List;

/**
 * 分页对象
 * 
 * @author Sid Liu
 * 
 *         Nov 19, 2009
 */
public class PageBean<E> {
	public static final String	SORT_DESC	= "desc";
	public static final String	SORT_ASC	= "asc";

	/**
	 * 当前页
	 */
	private int					currentPage;

	/**
	 * 满足条件总记录数
	 */
	private int					totalRows;

	/**
	 * 每页显示记录数
	 */
	private int					rowsPerPage;

	private String				sortColumnName;
	private String				sortDirection;

	/**
	 * 查询出来的数据
	 */
	private List<E>				items;

	public PageBean() {
	}

	public PageBean(int currentPage, int rowsPerPage, String sortColumnName,
			String sortDirection) {
		this.currentPage = currentPage;
		this.rowsPerPage = rowsPerPage;
		this.sortColumnName = sortColumnName;
		this.sortDirection = sortDirection;
	}

	public PageBean(int currentPage, int totalRows, int rowsPrePage,
			List<E> items) {
		this.currentPage = currentPage;
		this.totalRows = totalRows;
		this.rowsPerPage = rowsPrePage;
		this.items = items;
	}

	public String getSortColumnName() {
		return sortColumnName;
	}

	public void setSortColumnName(String sortColumnName) {
		this.sortColumnName = sortColumnName;
	}

	public String getSortDirection() {
		return sortDirection;
	}

	public void setSortDirection(String sortDirection) {
		this.sortDirection = sortDirection;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public int getRowsPerPage() {
		return rowsPerPage;
	}

	public void setRowsPerPage(int rowsPerPage) {
		this.rowsPerPage = rowsPerPage;
	}

	public List<E> getItems() {
		return items;
	}

	public void setItems(List<E> items) {
		this.items = items;
	}

	/**
	 * 得到总页数
	 * 
	 * @return
	 */
	public int getTotalPages() {
		if (totalRows == 0)
			return 1;
		return (totalRows + rowsPerPage - 1) / rowsPerPage;
	}

	/**
	 * 得到首页页号
	 * 
	 * @return
	 */
	public int getTopPageNo() {
		return 1;
	}

	/**
	 * 得到上一页页号
	 * 
	 * @return
	 */
	public int getPreviousPageNo() {
		if (currentPage == 1) {
			return 1;
		}
		return currentPage - 1;
	}

	/**
	 * 得到下一页页号
	 * 
	 * @return
	 */
	public int getNextPageNo() {
		if (currentPage == getBottomPageNo()) {
			return getBottomPageNo();
		}
		return currentPage + 1;
	}

	/**
	 * 得到最后一页页号
	 * 
	 * @return
	 */
	public int getBottomPageNo() {
		return getTotalPages();
	}
}
